﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XnaColor = Microsoft.Xna.Framework.Color;
using Microsoft.Xna.Framework;

namespace ColonisatorGame
{
    public class Animation
    {
        /// <summary>
        /// La durée de l'animation en ms
        /// </summary>
        public double Time { get; set; }

        private XnaColor _currentColor;
        private AnimationState _cuurentState;
        private XnaColor _startColor;
        
        public Animation(XnaColor startColor)
        {
            _currentColor = startColor;
            _startColor = startColor;
        }

        public void Start()
        {
            this._cuurentState = AnimationState.Descending;
        }

        public XnaColor Cancel()
        {
            return _startColor;
        }

        public XnaColor Update(GameTime gameTime)
        {            
            if (this._cuurentState == AnimationState.Descending)
            {
                this._currentColor.A -= 5;
                this._currentColor.R -= 5;
                if (this._currentColor.A == 0)
                    this._cuurentState = AnimationState.Ascending;
            }
            else if (this._cuurentState == AnimationState.Ascending)
            {
                this._currentColor.A += 5;
                this._currentColor.R += 5;
                if (this._currentColor.A == 255)
                    this._cuurentState = AnimationState.Descending;
            }
            return _currentColor;
        }
    }

    public enum AnimationState
    {
        Ascending = 0,
        Descending = 1
    }

}
